!function ($) {
    var manwei = {
        page:0,
        curMove:null,//当前移动的
        noCurMove:null,//非当前移动
        location:"l",
        moveDirection:"l",
        moveOldDirection:"l",
        changeUi:5,
        init:function(){
            if($(".m_picwrap").length == 0) return;
            this.initDom();
            this.initEvent();
            this.bodyWidth = $("body").width();
            this.prevwrapWidth = this.prev.offset().left+69;//左边宽度
            this.moveLi = $(".m_c01 li").eq(0).width()-1;//单个的值
            this.moveLength = this.moveLi * 5;//移动范围
            this.curMove = this.m_picwrap;
            var liNum = $(".m_c01 li").length;
            this.layerWidth = liNum*this.moveLi/2;//原层宽度

            manwei.updateUi(0);
        },
        initDom:function(){
            this.prev = $(".m_larrow .prev");//左滑动
            this.next = $(".m_rarrow .next");//右滑动
            this.m_picwrap = $(".m_picwrap");//移动层
            this.noCurMove = this.cloneDom = this.m_picwrap.clone();
            this.cloneDom.attr("clone","1");
            //this.threeCurMove = this.cloneDom2 = this.m_picwrap.clone();
            this.m_picwrap.before(this.cloneDom);
            //this.m_picwrap.after(this.cloneDom2);
        },
        initEvent:function(){
            this.prev.click(jQuery.proxy( this, "prevClick" ));
            this.next.click(jQuery.proxy( this, "nextClick" ));
            $(window).resize(function(){
                manwei.prevwrapWidth = manwei.prev.offset().left+69;//左边宽度
                if(manwei.moveDirection == "l"){
                    manwei.updateUi(0);
                }else{
                    manwei.updateUir(0);
                }
            });
        },
        prevClick:function(){
            //左边移动，当右边出现在可视区域，则将另一个节点放在当前节点后边
            this.page+=5;
            this.moveOldDirection = this.moveDirection;
            this.moveDirection = "l";
            console.log("prev:"+this.page);
            this.updateUi();
        },
        nextClick:function(){
            //右边移动，当左边出现在可视区域，则将另一个节点放在当前节点后边
            this.page-=5;
            this.moveOldDirection = this.moveDirection;
            this.moveDirection = "r";
            console.log("next:"+this.page);
            this.updateUir();
        },

        updateUi:function(time){
            manwei.uiPos(manwei.curMove, manwei.page, time);
            manwei.noUiPos(manwei.noCurMove, time);
        },
        updateUir:function(time){
            manwei.noUiPos(manwei.noCurMove, time);
            manwei.uiPos(manwei.curMove, manwei.page, time);
        },
        //动画移动位置
        curLeft:0,
        oldcurLeft:0,
        change2:false,
        location2:"r",
        uiPosi:0,
        uiPos:function(o, i, time){

            time = (time == 0 || time)? time : 3;
            this.oldcurLeft = this.curLeft;

            if(this.moveDirection == "l"){
                manwei.curLeft = manwei.prevwrapWidth - manwei.moveLi *i;
                setTimeout(function(){
                    if (window.applicationCache) {
                        o.css({
                            "left":manwei.curLeft+"px",
                            "transition": "left ."+time+"s",
                            "-moz-transition": "left ."+time+"s",
                            "-ms-transition": "left ."+time+"s",
                            "-webkit-transition": "left ."+time+"s",
                            "-o-transition": "left ."+time+"s"
                        });
                    } else {
                        o.animate({
                            left: manwei.curLeft
                        }, time*100);
                    }
                }, 0);

            }else{
                if(this.page ==-this.changeUi*2 && !this.change2){
                    this.location2 = "l";


                    o.css({
                        left: (-manwei.layerWidth + manwei.nooldLeft)+"px",
                        "transition": "left 0s",
                        "-moz-transition": "left 0s",
                        "-ms-transition": "left 0s",
                        "-webkit-transition": "left 0s",
                        "-o-transition": "left 0s"
                    });
                    this.noCurMove.before(o);
                    this.change2 = true;
                }


                if(manwei.location2 =="r"){
                    manwei.curLeft = manwei.prevwrapWidth - manwei.moveLi *i;
                }else{
                    manwei.curLeft = -(manwei.layerWidth - manwei.noLeft);
                }
                setTimeout(function(){

                    if (window.applicationCache) {
                        o.css({
                            "left":manwei.curLeft+"px",
                            "transition": "left ."+time+"s",
                            "-moz-transition": "left ."+time+"s",
                            "-ms-transition": "left ."+time+"s",
                            "-webkit-transition": "left ."+time+"s",
                            "-o-transition": "left ."+time+"s"
                        });
                    } else {
                        o.animate({
                            left: manwei.curLeft
                        }, time*100);
                    }
                    setTimeout(function(){
                        if(manwei.page <= -manwei.changeUi*2){//做移动改变方向
                            manwei.page=0;
                            manwei.change2 = false;
                            manwei.location2 = "r";
                            var o = manwei.curMove;
                            manwei.curMove= manwei.noCurMove;
                            manwei.noCurMove= o;
                        }
                    }, 60)
                }, 0);
            }


        },
        //非动画移动位置
        change:false,
        noLeft:0,
        nooldLeft:0,
        noUiPos:function(o, time){

            time = (time == 0 || time)? time : 3;
            manwei.nooldLeft = manwei.noLeft;
            if(this.moveDirection == "l"){
                if(this.page >=this.changeUi && (!this.change || this.moveOldDirection=="r")){
                    this.location = "r";
                    o.css({
                        left: manwei.oldcurLeft>0 ?(manwei.oldcurLeft+manwei.layerWidth)+"px": (manwei.layerWidth+manwei.curLeft-(manwei.oldcurLeft-manwei.curLeft))+"px",
                        "transition": "left 0s",
                        "-moz-transition": "left 0s",
                        "-ms-transition": "left 0s",
                        "-webkit-transition": "left 0s",
                        "-o-transition": "left 0s"
                    });
                    this.curMove.after(o);
                    this.change = true;
                }



                if(manwei.location == "l"){
                    manwei.noLeft = -(manwei.layerWidth-manwei.curLeft);
                }else{
                    manwei.noLeft = manwei.layerWidth+manwei.curLeft;
                }

                setTimeout(function(){


                    if (window.applicationCache) {
                        o.css({
                            "left":manwei.noLeft+"px",
                            "transition": "left ."+time+"s",
                            "-moz-transition": "left ."+time+"s",
                            "-ms-transition": "left ."+time+"s",
                            "-webkit-transition": "left ."+time+"s",
                            "-o-transition": "left ."+time+"s"
                        });
                    } else {
                        o.animate({
                            left: manwei.noLeft
                        }, time*100);
                    }
                    setTimeout(function(){
                        if(manwei.page >=manwei.changeUi*2){//做移动改变方向
                            manwei.page=0;
                            manwei.change = false;
                            var o = manwei.curMove;
                            manwei.curMove= manwei.noCurMove;
                            manwei.location = "l";
                            manwei.noCurMove= o;
                        }
                    }, 60)

                } ,0);
            }else{
                if(this.page >=this.changeUi && !this.change){
                    this.location = "r";
                    o.css({
                        left: (manwei.oldcurLeft+manwei.layerWidth)+"px",
                        "transition": "left 0s",
                        "-moz-transition": "left 0s",
                        "-ms-transition": "left 0s",
                        "-webkit-transition": "left 0s",
                        "-o-transition": "left 0s"
                    });
                    this.curMove.after(o);
                    this.change = true;
                }

                if(this.page == 0 && this.change){
                    this.location = "l";
                    o.css({
                        left: -(manwei.oldcurLeft+manwei.layerWidth)+"px",
                        "transition": "left 0s",
                        "-moz-transition": "left 0s",
                        "-ms-transition": "left 0s",
                        "-webkit-transition": "left 0s",
                        "-o-transition": "left 0s"
                    });
                    this.curMove.after(o);
                    this.change = true;
                }
                if(manwei.location == "l"){
                    manwei.noLeft = -(manwei.layerWidth-(manwei.prevwrapWidth - manwei.moveLi *this.page));
                }else{
                    manwei.noLeft = manwei.layerWidth+manwei.curLeft;
                }

                setTimeout(function(){


                    if (window.applicationCache) {
                        o.css({
                            "left":manwei.noLeft+"px",
                            "transition": "left ."+time+"s",
                            "-moz-transition": "left ."+time+"s",
                            "-ms-transition": "left ."+time+"s",
                            "-webkit-transition": "left ."+time+"s",
                            "-o-transition": "left ."+time+"s"
                        });
                    } else {
                        o.animate({
                            left: manwei.noLeft
                        }, time*100);
                    }
                    setTimeout(function(){
                        if(manwei.page >=manwei.changeUi*2){//做移动改变方向
                            manwei.page=0;
                            manwei.change = false;
                            var o = manwei.curMove;
                            manwei.curMove= manwei.noCurMove;
                            manwei.noCurMove= o;
                        }
                    }, 60)

                } ,0);
            }

            }




    }




    $(function($) {
        manwei.init();
        //其它
        if($("#slider").length > 0){
            var m_dian = $(".m_dian"),
                l = Math.ceil($("#slider li").length/3),
                i = 0 ,
                html = '';
            if(l > 1){
                for(; i < l;i++){
                    if(i == 0){
                        html+='<i data-num="'+1+'" class="cur"></i>';
                    }else{
                        html+='<i data-num="'+(i*3+1)+'" ></i>';
                    }
                }
                m_dian.html(html).show();
                /*m_dian.children("i").each(function(){
                 $(this).click(function(){
                 m_dian.children("i").removeClass("cur");
                 $(this).addClass("cur");
                 var num = $(this).attr("data-num");
                 });
                 });*/
            }else{
                m_dian.hide();
            }
            var slide = jQuery('#slider').jcarousel({
                scroll:3,
                wrap: 'circular',
                initCallback: function(carousel){
                    $(".m_dian i").bind('click', function() {
                        $(".m_dian i").removeClass("cur");
                        $(this).addClass("cur");
                        //$(".m_dian i").eq(Math.floor(p/3)).addClass("cur");
                        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).attr("data-num")));
                        return false;
                    });
                },
                itemVisibleOutCallback: {
                    onAfterAnimation: function(r,m,p){

                    }
                }
            });

            $(".m_next,#newdongtai,.goTarget").each(function(){
                $(this).click(function(){
                    var top = $("#"+$(this).attr("data-target")).offset().top;
                    $('html, body').animate({scrollTop:top-58}, 'slow');
                });
            });

            $(".m_moviejd li").each(function(i){
                $(this).attr("data-num",i)
                $(this).click(function(){
                    $(".m_moviejd li").removeClass("cur");
                    $(this).addClass("cur");
                    $(".m_movienr").hide();
                    $(".m_movienr").eq(i).show();
                });
            });

            $(".m_movienr li").each(function(i){
                $(this).attr("data-tartget","m_moviewindow"+(i+1))
                $(this).click(function(){
                    var t = $(this).attr("data-tartget"),
                        pop = $(this).attr("data-pop");
                    if(pop =="1"){
                        return;
                    }
                   $("#"+t).show();
                });
            });
            $(".m_close").click(function(){
                $(".m_moviewindow").hide();
            });


            var indexSlider = {
                page:0,
                maxPage:2,
                init:function(){
                    this.initEvent();
                },
                initEvent:function(){

                    $("#m_watch .mprev").click(function(){
                        if($(this).hasClass("notprev")){
                            return;
                        }
                        indexSlider.page--;
                        $("#m_watch .mnext").removeClass("notnext");
                        if(indexSlider.page <= 0){
                            $("#m_watch .mprev").addClass("notprev");
                            indexSlider.page == 0;
                        }else{
                            $("#m_watch .mprev").removeClass("notprev");
                        }
                        indexSlider.updatteUi(indexSlider.page);
                    });
                    $("#m_watch .mnext").click(function(){
                        if($(this).hasClass("notnext")){
                            return;
                        }
                        indexSlider.page++;
                        $("#m_watch .mprev").removeClass("notprev");
                        if(indexSlider.page >= indexSlider.maxPage){
                            indexSlider.page == indexSlider.maxPage;
                            $("#m_watch .mnext").addClass("notnext");
                        }else{
                            $("#m_watch .mnext").removeClass("notnext");
                        }

                        indexSlider.updatteUi(indexSlider.page);
                    });
                },
                updatteUi:function(i){
                    $("#m_watch .m_contwrap,.m_watchlist li").fadeOut(300,function(){
                    });
                    $("#m_watch .m_contwrap").eq(i).fadeIn(600);
                    $(".m_watchlist li").eq(i).fadeIn(1000);
                }
            }
            var prev = $(".mprev");
            var next = $(".mnext");
            var indexSlider2 = {
                page:0,
                maxPage:0,
                init:function(){
                    this.initEvent();
                },
                initEvent:function(){

                    prev.eq(1).click(function(){
                        if($(this).hasClass("notprev")){
                            return;
                        }
                        indexSlider2.page--;
                        next.eq(1).removeClass("notnext");
                        if(indexSlider2.page <= 0){
                            prev.eq(1).addClass("notprev");
                            indexSlider2.page = indexSlider2.maxPage;
                        }else{
                            prev.eq(1).removeClass("notprev");
                        }
                        indexSlider2.updatteUi(indexSlider2.page);
                    });
                    next.eq(1).click(function(){
                        if($(this).hasClass("notnext")){
                            return;
                        }
                        indexSlider2.page++;
                        prev.eq(1).removeClass("notprev");
                        if(indexSlider2.page >= indexSlider2.maxPage){
                            indexSlider2.page == indexSlider2.maxPage;
                            next.eq(1).addClass("notnext");
                        }else{
                            next.eq(1).removeClass("notnext");
                        }

                        indexSlider2.updatteUi(indexSlider2.page);
                    });
                },
                updatteUi:function(i){
                    $(".m_apiclist").animate({
                        left: -1*i*486*2
                    }, 500);


                }
            }
            indexSlider.init();
            indexSlider2.init();
			   var iint, o;
           
        } $(".m_toplist li").each(function(){
                $(this).mouseover(function(){
                    var that = this;
                    if(o == this){
                        clearTimeout(iint)
                    }
                    $(that).children("div").slideDown(100);
                })
                $(this).mouseout(function(){
                    var that = this;
                    o = this;
                    iint = setTimeout(function(){
                        $(that).children("div").slideUp(100);
                    },300);
                })
            });
    });

}(jQuery);